﻿var xmlhttpisload = false;
var __XmlHttpPool__ = 
{ 
	m_MaxPoolLength : 10, 
	m_XmlHttpPool : [], 
	m_LoadingMode : 100,
	m_ShowLoading : true,
	__requestObject : function() 
	{ 
		var xmlhttp = null; 
		var pool = this.m_XmlHttpPool; 
		for ( var i=0 ; i < pool.length ; ++i ) 
		{ 
			if ( pool[i].readyState == 4 || pool[i].readyState == 0 ) 
			{ 
				xmlhttp = pool[i]; 
				break; 
			} 
		} 
		if ( xmlhttp == null ) 
		{ 
			return this.__extendPool(); 
		} 
		return xmlhttp; 
	}, 
	
	__extendPool : function() 
	{ 
		if ( this.m_XmlHttpPool.length < this.m_MaxPoolLength ) 
		{ 
			var xmlhttp = null; 
			if(window.XMLHttpRequest)   
			{   
			  	xmlhttp = new XMLHttpRequest(); 
				
			}else if(window.ActiveXObject){
				try 
				{ 
					xmlhttp = new ActiveXObject('MSXML2.XMLHTTP'); 
				} 
				catch(e) 
				{ 
					try 
					{ 
						xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); 
					} 
					catch(e2) {} 
				} 
			}
			if ( xmlhttp ) 
			{ 
				this.m_XmlHttpPool.push(xmlhttp); 
			} 
			return xmlhttp; 
		} 
	}, 
	 
	GetRemoteData : function(url, callback) 
	{ 
		return this.__receiveRemoteData(url, callback, 'GET', null); 
	}, 
	 
	PostRemoteData : function(url, callback, data) 
	{ 
		return this.__receiveRemoteData(url, callback, 'POST', data); 
	}, 
	 
	__receiveRemoteData : function(url, callback, httpmethod, data) 
	{ 
		var xmlhttp = this.__requestObject(); 
		if ( !xmlhttp ) 
		{ 
			return null; 
		}
		if(isPross()){return null;}

		xmlhttp.open(httpmethod, url, true); 
		if ( httpmethod == 'POST' )
		{
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}
		xmlhttp.onreadystatechange = function() 
		{	
			if ( xmlhttp.readyState == 1 ) 
			{ 
				xmlhttpisload = true;
				switch (__XmlHttpPool__.m_LoadingMode) {
					case 101 :
						callback('数据加载中,请稍候...');
						break;
					default :
						popAlert("<center><img src='/images/default/loading.gif' vspace='20'/></center>","正在连接,请稍候...",0);
				} 
			}
			if ( xmlhttp.readyState == 2 ) 
			{ 
				xmlhttpisload = true;
				switch (__XmlHttpPool__.m_LoadingMode) {
					case 101 :
						callback('数据加载中,请稍候...');
						break;
					default :
						popAlert("<center><img src='/images/default/loading.gif' vspace='20'/></center>","数据加载中,请稍候...",0);
				}
			}
			if ( xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete' ) 
			{ 
				xWin.closeWin("popAlert");
				xmlhttpisload = false;
				callback(xmlhttp.responseText); 
			} 
		}; 
		xmlhttp.send(data); 
		return xmlhttp; 
	},
	GetRemoteDataEx : function(url)
	{
		return this.__receiveRemoteDataEx(url, 'GET', null);
	},
	
	PostRemoteDataEx : function(url, data)
	{
		return this.__receiveRemoteDataEx(url, 'POST', data);
	},
	__testRemoteEx : function(url,httpmethod)
	{
		url="/agent.aspx?url="+escape(unescape(url));
		var xmlhttp = this.__requestObject();
		if ( !xmlhttp )
		{
			return -100;
		}
		xmlhttp.open(httpmethod, url, false);
		try
		{
			xmlhttp.send(null);
		}
		catch(e)
		{
			__Debug__(e, data); 
		}
			
		return xmlhttp.status;
	},
	__receiveRemoteDataEx : function(url, httpmethod, data)
	{
		if(url.substring(0,7)=="http://")
		{
			url="agent.aspx?url="+escape(unescape(url));
		}

		var xmlhttp = this.__requestObject();
		if ( !xmlhttp )
		{
			return null;
		}
		
		xmlhttp.open(httpmethod, url, false);
		if ( httpmethod == 'POST' )
		{
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}
		try
		{
			xmlhttp.send(data);
		}
		catch(e)
		{
			__Debug__(e, data); 
		}
		if ( xmlhttp.status == 200 )
		{
			return xmlhttp.responseText;
		}

	},
	ClearAll : function(){
		for ( var i=0 ; i < this.m_XmlHttpPool.length ; ++i )  
		{  
			this.m_XmlHttpPool[i]=null; 
		}  
	},
	CancelAll : function()  
	{  
		var extendPool = this.__extendPool;  
		this.__extendPool = function()  
		{  
			return null;  
		}  
		for ( var i=0 ; i < this.m_XmlHttpPool.length ; ++i )  
		{  
			this.m_XmlHttpPool[i].abort(); 
		}  
		this.__extendPool = extendPool;  
	} 
}; 
function isPross()
{
	if(xmlhttpisload){
		alert('数据正在读取中，请稍候......！！！！');
	}
	return xmlhttpisload;
};


/*窗口处理*/
var xWin =
{
	id : 'popAlert',
	hover : 'orange',
	normal : '#4560aa',//颜色设定;#3366cc 蓝色 55a065青色
	x0 : 0,
	y0 : 0,
	x1 : 0,
	y1 : 0,
	offx : 6,
	offy : 6,
	width : 400,
	height : 150,
	moveable : false,
	Left : 0,
	Top : 0,
	zIndex : 10000,
	obj : null,
	YesNoBtnValue : 0,
	
	/*关闭窗口*/
	cls : function(obj){
		var win = obj.parentNode.parentNode;
		win.style.display = "none";
		this.closeWin(win.id);
	},
	/*关闭窗口*/
	closeWin : function(fnDivId){
		if(Gel(fnDivId))
			Gel(fnDivId).style.display = "none";
		this.clearBg(fnDivId+"_frame");
	},
	//获得焦点;
	getFocus : function(obj){
		if(obj.style.zIndex!=this.zIndex){
			if(this.id=='popAlert')
				return;
			this.zIndex = this.zIndex + 2;
			var idx = this.zIndex;
			obj.style.zIndex=idx;
		}
	},
	
	/*开始拖动*/
	startDrag : function(obj){
		if(event.button==1){
			//锁定标题栏;
			obj.setCapture();
			//定义对象;
			var win = obj.parentNode;
			//记录鼠标和层位置;
			this.x0 = event.clientX;
			this.y0 = event.clientY;
			this.x1 = parseInt(win.style.left);
			this.y1 = parseInt(win.style.top);
			//记录颜色;
			this.moveable = true;
		}
	},
	/*	拖动;*/
	drag : function(obj){
		if(this.moveable){
			var win = obj.parentNode;
			var x2 = (this.x1 + event.clientX - this.x0<top.window.document.body.clientWidth-this.width-8)?(this.x1 + event.clientX - this.x0):window.document.body.clientWidth-this.width-8;
			x2 = (x2>0)?x2:0;
			var y2 = (this.y1 + event.clientY - this.y0<top.window.document.body.clientHeight-this.height-60)?(this.y1 + event.clientY - this.y0):top.window.document.body.clientHeight-this.height-60;
			y2 = (y2>0)?y2:0;
			win.style.left = x2;
			win.style.top  = y2;
		}
	},
	/*	停止拖动;*/
	stopDrag : function(obj){
		if(this.moveable){
			obj.releaseCapture();
			this.moveable = false;
		}
	},
	initialize : function(divId){
		var newDiv = Gel(divId);
		if(newDiv==null){
			newDiv = document.createElement( "div" );
			newDiv.id=divId;
			newDiv.innerText="";
			newDiv.setAttribute('class','popwin');
			newDiv.setAttribute('className','popwin');
			document.body.insertAdjacentElement("beforeEnd",newDiv);
		}
		return newDiv;
	},
	/*加载数据 mode=0为读取状态,提关闭按钮, mode=1为有关闭和确定提示窗口,mode=2为正常模式*/
	popWin : function(id,w,h,fnTitle,fnMsg,l,t,z,mode){
		this.id		=id;
		this.zIndex	=(z)?z:10000;//z-index;
		this.width 	= w;
		this.height = h;
		this.mode 	= (mode!=null)?mode:2;
		var obj 	= new this.initialize(this.id);
		this.Left 	= (l)?l:document.documentElement.clientWidth/2-w/2;
		this.Top 	= (t)?t:document.documentElement.clientHeight/3;
		obj.style.left		=this.Left+document.documentElement.scrollLeft;//window.document.body.clientWidth/2-200
		obj.style.top		=this.Top+document.documentElement.scrollTop;//window.document.body.clientHeight/3;
		obj.style.width		=this.width;
		obj.style.height	= (this.mode==1)?this.height+32:this.height;
		obj.style.zIndex	=this.zIndex-1;
		obj.style.display	="";
		var HtmlStr = "<div class='thead'"
		+ "style='"
		+ "width:" + (this.width) + ";"
		+ "height:20px;"
		+ "' "
		+ "onmousedown='xWin.startDrag(this)' "
		+ "onmouseup='xWin.stopDrag(this)' "
		+ "onmousemove='xWin.drag(this)' "
		+ ">"
		+ "<span class='title'>"+fnTitle+"</span>"
		if(this.mode>0){
			HtmlStr =  HtmlStr +"<a class='btn' onclick='xWin.cls(this)'>r</a>"
		}
		HtmlStr =  HtmlStr + "</div>"
		+ "<div class='tContents' style='"
		+ "width:"+(this.width-6)+";"
		+ "height:" + (this.height-2*12-2) + ";"
		+ "'>" + fnMsg + "</div>"
		if(this.mode==1){
			HtmlStr =  HtmlStr +'<div class="cmdline"><button accesskey="O" onclick="xWin.closeWin(\''+this.id+'\')">确定(O)</button></div>';
		}
		//+ "<iframe frameborder=0 style=\"position:absolute;width:1280px;height:1024px;top:0px;left:0px;border:none;display:block;z-index:-1\"></iframe>";
		if(fnMsg!=null) TM.setInnerHTML(obj,HtmlStr);
		//if(fnMsg!=null) obj.innerHTML = HtmlStr;
		this.initBg(id+"_frame",((z)?z:10000)-5);
	},
	
	popAlert : function(fnMsg,fnTitle,fMode){
		this.popWin("popAlert",300,100,fnTitle,fnMsg,0,0,20000,(fMode==null)?1:fMode);
	},
	popCheckCode : function(fnTitle){
		this.popWin("popCheckCode",270,120,fnTitle,'<div style="padding-left:15px;padding-bottom:4px;padding-top:4px;text-align:left">'
			+'请填写右侧图片中的小写字母和数字</div>'
			+'<div style="float:left;padding-right:4px;padding-left:15px;text-align:left"><input id="vCode" style="border:1px #999 solid;line-height:20px;height:20px;width:80px;font-size:14px;font-family:Geneva"  accesskey="V" type="text" maxlength="6"/></div>'
			+'<div style="float:left;text-align:left;padding-top:1px;"><img src="/ImgCode.aspx" alt="看不清楚,请双击此处更换验证码!!!" name="imgCode" align="absmiddle" id="imgCode" ondblclick="this.src=\'/ImgCode.aspx?\'+Math.random();" /></div>'
			+'<div style="padding-left:15px;clear:left;padding-top:8px"><input class="btnA_1" type="button" value="确定(O)" accesskey="O" style="width:60px;" onclick="if(TM.doCheckedCode(\'vCode\'))xWin.closeWin(\'popCheckCode\')"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" style="width:60px;" class="btnA_1" value="取消(C)" accesskey="C" onclick="xWin.closeWin(\'popCheckCode\')"/></div>'
			,0,0,20000,2);
		if(Gel('vCode')!=null)Gel('vCode').focus();
	},
	popConfirm : function(fnMsg,fnTitle){
		var str='<font style="font-size:14px;color:#000066;pading-top:8px;">'+fnMsg+'</font><br/>'
		+"<center style='line-height:30px;padding-top: 10px;'><button style='line-height:20px;' onclick='xWin.YesNoBtnValue=1;xWin.closeWin(\"popAlert\")'>  是 (Yes)  </button>"
		+"　　<button style='line-height:20px;' onclick='xWin.YesNoBtnValue=0;xWin.closeWin(\"popAlert\")'>  否 (No)  </button></center>"
		this.popAlert(str,fnTitle);
		return this.YesNoBtnValue;
	},
	initBg : function(argBgId,argIndex){
		var bgDiv = Gel(argBgId);
		if(!bgDiv){
			var bgDiv = document.createElement( "div" );
			bgDiv.id  = argBgId;
			bgDiv.style.position="absolute";
			bgDiv.style.backgroundColor="#333333";
			bgDiv.style.left   =document.documentElement.scrollLeft;
			bgDiv.style.top    =document.documentElement.scrollTop;
			document.body.insertAdjacentElement("beforeEnd",bgDiv);
		}
		bgDiv.style.width  =document.documentElement.scrollWidth;
		var height = top.window.document.getElementById('myWindow').offsetHeight;
		height = (document.documentElement.scrollHeight>height)?document.documentElement.scrollHeight:height;
		bgDiv.style.height =height;//screen.availHeight;
		bgDiv.style.zIndex =argIndex?argIndex:900;
		bgDiv.style.filter ="alpha(opacity=5)";
		bgDiv.style.display="";
		bgDiv.innerHTML="<iframe frameborder=0 style=\"position:absolute;width:"+document.documentElement.scrollWidth+"px;height:"+(height-55)+"px;filter:alpha(opacity=0);top:0px;left:0px;border:none;z-index:-1\"></iframe>";
	},
	clearBg : function(argBgId){
		if(Gel(argBgId))
			Gel(argBgId).style.display='none';
		document.body.style.overflow="auto";
	}

}
function Gel(id){
	return document.getElementById(id);
}
function popAlert(fnMsg,fnTitle,fMode){
	xWin.popAlert(fnMsg,fnTitle?fnTitle:'提示',fMode);
}
	//处理验证码
